package com.x_memteor.base_master.base;

import android.content.Context;
import android.util.Log;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @author: X_Meteor
 * @description: 类描述
 * @version: V_1.0.0
 * @date: 2018/3/14 22:50
 * @company:
 * @email: lx802315@163.com
 */
public abstract class BaseObserverWithBean<T> implements Observer<BaseEntityWithBean<T>> {

    private static final String TAG = "BaseObserver";

    @Override
    public void onNext(BaseEntityWithBean<T> value) {
        if (value.getState() == 1) {
            T t = (T) value.getData();
            onHandleSuccess(t);
        } else {
            onHandleError(value.getMsg());
        }
    }

    @Override
    public void onError(Throwable e) {
        Log.e(TAG, "error:" + e.getMessage());
        onHandleError(e.getMessage());
    }

    @Override
    public void onComplete() {
        Log.d(TAG, "onComplete");
    }

    @Override
    public void onSubscribe(Disposable d) {
        Log.d(TAG, "onSubscribe: ");
    }

    protected abstract void onHandleSuccess(T t);

    protected abstract void onHandleError(String msg);
}

